package org.jeecg.modules.simulator.factory.station;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.simulator.factory.station.json.Stationbs;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: gp
 * @description:
 * @author: renzhg
 * @create: 2024-08-08 09:08
 **/
public class StationJsonRead  implements  StationLoader{


    public List<Stationbs> readStationBs(String linepath){
        List<Stationbs> stationbsList=new ArrayList<>();
        try {
            String jsonString = new String(Files.readAllBytes(Paths.get(linepath)));
            JSONArray jsonArray = JSON.parseArray(jsonString);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Stationbs stationbs = JSON.parseObject(jsonObject.toString(), Stationbs.class);
                stationbsList.add(stationbs);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stationbsList;

    }




    @Override
    public List<Stationbs> loadStation() {
        return readStationBs("D:/aaaa/station.json");

    }
}